# from qqbot import QQBot
import re


# class MyQQBot(QQBot):
#     def onPollComplete(self, msgType, from_uin, buddy_uin, message):
#         if message == '-hello':
#             self.send(msgType, from_uin, '你好，我是QQ机器人')
#         elif message == '-stop':
#             self.stopped = True
#             self.send(msgType, from_uin, 'QQ机器人已关闭')
#         elif pattern.search(message):
#             str = message[1:]
#             self.send(msgType,from_uin,'http://xx2018.cn/index.php?r=l&kw=' + str)
#
# pattern = re.compile(u'买')
# myqqbot = MyQQBot()
# myqqbot.Login()
# myqqbot.PollForever()
import urllib.request

from qqbot import QQBotSlot as qqbotslot, RunBot
@qqbotslot
def onQQMessage(bot, contact, member, content):
    if content == '-hello':
        bot.SendTo(contact, '''<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="1" templateID="1" action="web" brief="[分享] 可以每天都能免费获得5000赞的软件" sourceMsgId="0" url="http://pan.baidu.com/s/1qXF8aBy" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2"><picture cover="http://url.cn/50JsIJB" w="0" h="0" /><title>可以每天都能免费获得5000赞的软件</title><summary>让你告别卖赞软件,不要积分,不要充值即可获得赞</summary></item><source name="联调测试应用" icon="http://url.cn/5gHkHdw" url="http://url.cn/KU2lBe" action="app" a_actionData="com.tencent.sample" i_actionData="tencent222222://" appid="222222" /></msg>''')
    elif content == '-stop':
        bot.SendTo(contact, 'QQ机器人已关闭')
        bot.Stop()
    elif pattern.search(content):
        str = content[1:]
        str = urllib.request.quote(str)
        bot.SendTo(contact, 'http://xx2018.cn/index.php?r=l&kw= ' + str)

pattern = re.compile(u'买')
#if __name__ == '__main__':RunBot()
